#ifndef __TEMP_CONTROL_H__
#define __TEMP_CONTROL_H__

#define		PWM_OUT(x)		P30 = x

//PID结构体
typedef struct 
{
	int16_t  Sv;			//用户设定值
	float  Pv;			//当前温度

	float  Kp;			//比例系数
	int16_t  T_Calc;		//PID计算周期--采样周期
	float  Ki;			//积分项系数
	float  Kd;			//微分项系数

	int16_t  EkNow;			//本次偏差
	int16_t  EkLast; 		//上次偏差
	int32_t  SEk;			//历史偏差之和

	int16_t  PID_OUT0;		//激励常数

	float  PID_OUT;

	uint16_t C10ms;

	uint32_t pwmcycle;
}pid_Struct_t;

extern xdata pid_Struct_t pid;

extern xdata uint8_t	pid_self_first_status_flag;	
extern xdata uint8_t	Step_Auto;					
extern xdata uint8_t	PID_read;					
extern xdata uint8_t	PID_Auto_Deal;				
extern xdata uint16_t	PID_Auto_Time;				
extern xdata uint8_t	zero_across_counter;		
extern xdata uint16_t	time_low;					
extern xdata uint16_t	time_high;
extern xdata int16_t 	temp_low;
extern xdata int16_t 	temp_high;
extern xdata uint8_t	PID_Auto_flag;
//int16_t temp_Sample_Filter(float temp);
float temp_Sample(uint16_t 	adc_value);
uint16_t middleValueFilter(void);
void PID_Init(void);
void ReadTemp(void);
void PID_Calculate(void);
void PID_out(void);
void PID_Save(void);
void PID_Auto(void);
uint8_t PID_Auto_Deal_judge(void);

#endif
